package cate.game.play.skill.passive.talent;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.AppendMoveHandler;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.proce.result.SkillAnounceResult;
import cate.game.play.proce.turn.TurnCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 击杀敌人时，有100%概率进行一次普攻，造成120%伤害
 */
public class 追杀PH extends PassiveHandler implements AppendMoveHandler {

	private int 概率;

	private double 额外系数;

	//概率=10000&额外系数=2000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		额外系数 = args.getWDouble("额外系数", 0d);
	}

	@Override
	public void onOwnerMoveDone(MoveCtx move, TimeActionCtx action) {
		if (move.isAppend()) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		if (move.stat.getTotalKill(skill.owner.getPid()) <= 0) {
			return;
		}
		Skill attack = skill.owner.skill.getAttack();
		if (attack == null) {
			return;
		}
		if (!XT.chance(概率)) {
			return;
		}
		AppendMove append = new AppendMove(skill.owner, attack, this);
		attack.param.addHpCfgByCoeff(额外系数);
		move.getTurn().addAppend(append);
	}

	@Override
	public boolean inValid(TurnCtx turn, AppendMove appendMove) {
		return false;
	}

	@Override
	public void beforeAppendMove(TurnCtx turn, AppendMove appendMove) {
		turn.buildTimeAction().addResult(new SkillAnounceResult().skillSet(this.skill));
	}

	@Override
	public void afterAppendMove(TurnCtx turn, AppendMove appendMove) {

	}

	@Override
	public void onAppendMoveFail(TurnCtx turn, AppendMove appendMove) {

	}
}
